/**
*
* @title 基本使用
* @description simpletable创建
*
*/
import React, { Component } from 'react';
import { createPage, base } from 'nc-lightapp-front';

const { NCButton } = base;
let meta = {};
let data = {};

class Demo1 extends Component {
  constructor(props) {
    super(props);
    props.use.table('tableBank');
  }

  componentWillMount() {
    const { table } = this.props;
    this.props.meta.setMeta(meta);
  }

  componentDidMount() {
      if(this.props.tcdata != {}){
          var obj = JSON.parse(this.props.tcdata);
          console.log(obj);
          data.rows=[];
          for (let index = 0; index < obj.length; index++) {
            let amount = 0;
            if (obj[index].debitamount!=0E-8) {
                amount = obj[index].debitamount;
               }else if (obj[index].creditamount!=0E-8) {
                amount = obj[index].creditamount;
               }
              let row = {
                status: '0',
                expandedRow: true,
                values:{
                    // forganization: {
                    //     value: obj[index].forganization
                    //   },
                      credentialsnum: {
                        value: obj[index].credentialsnum
                      },
                      accountname: {
                        value: obj[index].accountname
                      },
                      credentialsname: {
                        value: obj[index].credentialsname
                      },
                      subject: {
                        value: obj[index].subcode+"\\"+obj[index].subname
                      },
                      auxiliaryaccount: {
                        value: obj[index].auxiliaryaccount
                      },
                      dbilldate: {
                        value: obj[index].currencyname
                      },
                      amount: {
                        value: amount
                      },
                      localdebitamount: {
                        value: obj[index].localdebitamount
                      },
                      localcreditamount: {
                        value: obj[index].localcreditamount
                      },
                      abstract: {
                        value: obj[index].abstract
                      }
                }
              }
              data.rows.push(row);
          }
      }
    this.props.table.setAllTableData('tableBank', data);
  }

  render() {
    const { table } = this.props;
    const { createSimpleTable } = table;
    return (
      <div>
        {createSimpleTable('tableBank', {
        //   showCheck: true,
          showIndex: true,
          height:400,
          lazyload: false
        })}
      </div>
    );
  }
}

export default createPage({})(Demo1);

data = {
  rows: [
    {
      status: '0',
      expandedRow: true,
      values: {
        // forganization: {
        //   value: '1'
        // },
        credentialsnum: {
          value: '1'
        },
        accountname: {
          value: '1'
        },
        credentialsname: {
          value: '1'
        },
        subject: {
          value: '1'
        },
        auxiliaryaccount: {
          value: '1'
        },
        dbilldate: {
          value: '1'
        },
        amount: {
          value: '1'
        },
        localdebitamount: {
          value: '1'
        },
        localcreditamount: {
          value: '1'
        },
        abstract: {
          value: '1'
        }
      }
    }
  ]
};

meta = {
  tableBank: {
    moduletype: 'table',
    pagination: true,
    items: [
        // {
        //     itemtype: 'label',
        //     maxlength: '19',
        //     label: '财务组织',
        //     width: '200px',
        //     visible: true,
        //     disabled: true,
        //     attrcode: 'forganization'
        // },
      {
        itemtype: 'label',
        maxlength: '20',
        visible: true,
        width: '55px',
        label: '凭证号',
        disabled: true,
        attrcode: 'credentialsnum'
      },
      {
        itemtype: 'label',
        maxlength: '19',
        label: '核算账簿',
        width: '200px',
        visible: true,
        disabled: true,
        attrcode: 'accountname'
      },
      {
        itemtype: 'label',
        maxlength: '20',
        label: '凭证类型',
        width: '80px',
        required: true,
        visible: true,
        attrcode: 'credentialsname',
      },
      
      {
        itemtype: 'label',
        maxlength: '40',
        visible: true,
        width: '140px',
        label: '会计科目',
        attrcode: 'subject',
      },
      {
        itemtype: 'label',
        maxlength: '20',
        width: '200px',
        label: '辅助核算',
        visible:true,
        required: true,
        disabled: true,
        attrcode: 'auxiliaryaccount'
      },
      {
        itemtype: 'label',
        maxlength: '19',
        visible: true,
        width: '80px',
        label: '币种',
        required: true,
        attrcode: 'dbilldate'
      },
      {
        itemtype: 'label',
        maxlength: '20',
        visible: true,
        label: '原币',
        width: '100px',
        required: true,
        attrcode: 'amount'
      },
      {
        itemtype: 'label',
        maxlength: '20',
        visible: true,
        label: '账簿本币（借方）',
        width: '100px',
        required: true,
        attrcode: 'localdebitamount'
      },
      {
        itemtype: 'label',
        maxlength: '20',
        visible: true,
        label: '账簿本币（贷方）',
        width: '100px',
        required: true,
        attrcode: 'localcreditamount'
      },
      {
        itemtype: 'label',
        maxlength: '20',
        visible: true,
        label: '摘要',
        width: '140px',
        required: true,
        attrcode: 'abstract'
      },
    ]
  }
};